package cn.shop.gateway.utils;

/**
 * @author : 李一涵
 * @date : Created in 2021-12-8 10:26
 * @description :
 */
public class ResponseInfo<T> {

    private String msg;
    private Integer code;
    private T data;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static  <T> ResponseInfo<T> ok() {
        ResponseInfo<T> info = new ResponseInfo<>();
        info.setCode(1);
        info.setMsg("");
        return info;
    }

    public static  <T> ResponseInfo<T> ok(T t) {
        ResponseInfo<T> info = new ResponseInfo<>();
        info.setCode(1);
        info.setMsg("");
        info.setData(t);
        return info;
    }

    public static <T> ResponseInfo<T> fail(String msg) {
        ResponseInfo<T> info = new ResponseInfo<>();
        info.setCode(0);
        info.setMsg(msg);
        return info;
    }

    @Override
    public String toString() {
        return "{" +
                "\"msg\":\"" + msg + "\"" +
                ", \"data\":" + data + "" +
                ", \"code\":" + code +
                '}';
    }
}
